<template>
  <el-card v-for="(item, index) in showdata" :key="index" class="box-card">
    <template #header>
      <div class="card-header">
        <div v-html="item.name"></div>
      </div>
    </template>
    <el-button style="float: right" type="primary" @click="jump(item.id)"
      >去答卷</el-button
    >
    <br />
    <div v-html="'归属：' + item.gradeLevel"></div>
    <br />
    <div v-html="'学科：' + item.subjectId"></div>
    <br />
    <div v-html="'试卷种类：' + item.paperType"></div>
    <br />
    <div v-html="'满分：' + item.score"></div>
    <br />
  </el-card>
  <el-pagination
    v-model:currentPage="showform.pageIndex"
    v-model:page-size="showform.pageSize"
    :page-sizes="[5, 10, 20, 50]"
    :small="small"
    :disabled="disabled"
    :background="background"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
</template>

<script setup>
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import router from '@/router'
import { getsubject } from '@/api/subject'
import { mydata } from '@/api/user'
import {
  getexamdata,
  getpaperlists,
  deletepaper,
  getpaperfromid
} from '@/api/paper'
// 获取试卷信息
const pdata = ref([])
const total = ref()
const inip = async () => {
  const pform = ref({
    pageIndex: 1,
    pageSize: 10000
  })
  const res = await getpaperlists(pform.value)
  pdata.value = res.data.data.list
  total.value = pdata.value.length
  while (!pdata.value) {
    if (pdata.value) {
      break
    }
  }
  getshowdata()
}
const papermap = ref([
  '未知',
  '固定试卷',
  '未知',
  '未知',
  '时段试卷',
  '已批改',
  '任务试卷'
])
// 获取学科列表 用于映射
const subjectmap = ref([])
const inisubmap = async () => {
  const res = await getsubject()
  for (let i in res.data.data) {
    subjectmap.value[res.data.data[i].id] = res.data.data[i].name
  }
}
inisubmap()
//  获取展示信息
const showdata = ref([])
const showform = ref({
  pageIndex: 1,
  pageSize: 5
})
const getshowdata = () => {
  console.log(pdata.value)
  let temp = []
  for (
    let i = (showform.value.pageIndex - 1) * showform.value.pageSize;
    i < showform.value.pageSize * showform.value.pageIndex;
    i++
  ) {
    if (pdata.value[i]) temp.push(pdata.value[i])
  }
  for (let i = 0; i < temp.length; i++) {
    if (temp[i].gradeLevel === 1) temp[i].gradeLevel = '计算机'
    else temp[i].gradeLevel = '管理'
    temp[i].paperType = papermap.value[temp[i].paperType]
    temp[i].subjectId = subjectmap.value[temp[i].subjectId]
  }
  showdata.value = temp
  console.log('showdata', showdata.value)
}
const ini = () => {
  inip()
}
ini()
const handleSizeChange = (pageSize) => {
  showform.value.pageIndex = 1
  showform.value.pageSize = pageSize
  getshowdata()
}

const handleCurrentChange = (pagenum) => {
  showform.value.pageIndex = pagenum
  getshowdata()
}
const jump = (id) => {
  router.push({ name: 'sanswer', params: { id: id } })
}
</script>

<style lang="scss" scoped>
.header {
  padding-bottom: 16px;
  box-sizing: border-box;
}
</style>
